package ace.tool.generate.code.impl.resolver.ui.resolver;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * @author caspar
 * @date 2023/11/17 10:34
 */
public class UiTypeResolver {
  private final Class type;
  private static final Map<Class, String> DEFAULT_TYPE_MAP;
  private final Map<Class, String> typeMap;
  private final String defaultType;

  static {
    DEFAULT_TYPE_MAP = new HashMap<>();
    DEFAULT_TYPE_MAP.put(Integer.class, "number");
    DEFAULT_TYPE_MAP.put(Long.class, "string");
    DEFAULT_TYPE_MAP.put(String.class, "string");
    DEFAULT_TYPE_MAP.put(BigDecimal.class, "string");
    DEFAULT_TYPE_MAP.put(Boolean.class, "boolean");
    DEFAULT_TYPE_MAP.put(Date.class, "Date");
    DEFAULT_TYPE_MAP.put(LocalDateTime.class, "Date");
    DEFAULT_TYPE_MAP.put(UUID.class, "string");
    DEFAULT_TYPE_MAP.put(Short.class, "number");
    DEFAULT_TYPE_MAP.put(BigInteger.class, "string");
  }

  public UiTypeResolver(Class type) {
    this.typeMap = DEFAULT_TYPE_MAP;
    this.defaultType = "object";
    this.type = type;
  }

  public String resolve() {
    return this.typeMap.getOrDefault(type, defaultType);
  }
}
